**********************
** Code for figures **
**********************
clear all

* global inpath = "..." // Insert location of folder containing the dataset here
global inpath = "C:\Users\A1010571\Dropbox (BI Norwegian Business School)\WORKfiles\AFGEWERKTE TEKSTEN\AANVAARD Exit_Voice paper\LSQ"

use "$inpath\Data_for_graphs.dta", replace



* Figure 3 ALL

foreach x in BecomeIndep_yn SetOwnList_yn LeavePolitics_yn PointOthers_yn {
	ttest `x' if Indep==0, by(Generic)
	scalar lowerGen`x'=r(mu_2)-(r(sd_2)/sqrt(r(N_2))*1.96)
	scalar upperGen`x'=r(mu_2)+(r(sd_2)/sqrt(r(N_2))*1.96)
}

gen lower1 = lowerGenBecomeIndep_yn if Generic==1 & Indep==0
gen lower2 = lowerGenSetOwnList_yn if Generic==1 & Indep==0
gen lower3 = lowerGenLeavePolitics_yn if Generic==1 & Indep==0
gen lower4 = lowerGenPointOthers_yn if Generic==1 & Indep==0

gen upper1 = upperGenBecomeIndep_yn if Generic==1 & Indep==0
gen upper2 = upperGenSetOwnList_yn if Generic==1 & Indep==0
gen upper3 = upperGenLeavePolitics_yn if Generic==1 & Indep==0
gen upper4 = upperGenPointOthers_yn if Generic==1 & Indep==0

gen value1 = BecomeIndep_yn if Generic==1 & Indep==0
gen value2 = SetOwnList_yn if Generic==1 & Indep==0
gen value3 = LeavePolitics_yn if Generic==1 & Indep==0
gen value4 = PointOthers_yn if Generic==1 & Indep==0


foreach x in BecomeIndep_yn SetOwnList_yn LeavePolitics_yn PointOthers_yn {
	ttest `x' if Indep==0, by(Expense)
	scalar lowerExp`x'=r(mu_2)-(r(sd_2)/sqrt(r(N_2))*1.96)
	scalar upperExp`x'=r(mu_2)+(r(sd_2)/sqrt(r(N_2))*1.96)
}

replace lower1 = lowerExpBecomeIndep_yn if Expense==1 & Indep==0
replace lower2 = lowerExpSetOwnList_yn if Expense==1 & Indep==0
replace lower3 = lowerExpLeavePolitics_yn if Expense==1 & Indep==0
replace lower4 = lowerExpPointOthers_yn if Expense==1 & Indep==0

replace upper1 = upperExpBecomeIndep_yn if Expense==1 & Indep==0
replace upper2 = upperExpSetOwnList_yn if Expense==1 & Indep==0
replace upper3 = upperExpLeavePolitics_yn if Expense==1 & Indep==0
replace upper4 = upperExpPointOthers_yn if Expense==1 & Indep==0

replace value1 = BecomeIndep_yn if Expense==1 & Indep==0
replace value2 = SetOwnList_yn if Expense==1 & Indep==0
replace value3 = LeavePolitics_yn if Expense==1 & Indep==0
replace value4 = PointOthers_yn if Expense==1 & Indep==0


foreach x in BecomeIndep_yn SetOwnList_yn LeavePolitics_yn PointOthers_yn {
	ttest `x' if Indep==0, by(Metoo)
	scalar lowerMeT`x'=r(mu_2)-(r(sd_2)/sqrt(r(N_2))*1.96)
	scalar upperMeT`x'=r(mu_2)+(r(sd_2)/sqrt(r(N_2))*1.96)
}

replace lower1 = lowerMeTBecomeIndep_yn if Metoo==1 & Indep==0
replace lower2 = lowerMeTSetOwnList_yn if Metoo==1 & Indep==0
replace lower3 = lowerMeTLeavePolitics_yn if Metoo==1 & Indep==0
replace lower4 = lowerMeTPointOthers_yn if Metoo==1 & Indep==0

replace upper1 = upperMeTBecomeIndep_yn if Metoo==1 & Indep==0
replace upper2 = upperMeTSetOwnList_yn if Metoo==1 & Indep==0
replace upper3 = upperMeTLeavePolitics_yn if Metoo==1 & Indep==0
replace upper4 = upperMeTPointOthers_yn if Metoo==1 & Indep==0

replace value1 = BecomeIndep_yn if Metoo==1 & Indep==0
replace value2 = SetOwnList_yn if Metoo==1 & Indep==0
replace value3 = LeavePolitics_yn if Metoo==1 & Indep==0
replace value4 = PointOthers_yn if Metoo==1 & Indep==0

gen ones=1

preserve 

reshape long value lower upper, i(id Treatment) j(category)
collapse (mean) value lower upper, by(category Treatment)
sort category Treatment 
gen barposition=_n

twoway bar value barposition if(category==1 & Treatment==1), bcolor(black) barw(0.95) || bar value barposition if(category==1 & Treatment==2), bcolor(black%60) barw(0.95) || bar value barposition if(category==1 & Treatment==3), bcolor(black%20) barw(0.95) || bar value barposition if(category==2 & Treatment==1), bcolor(black) barw(0.95) || bar value barposition if(category==2 & Treatment==2), bcolor(black%60) barw(0.95) || bar value barposition if(category==2 & Treatment==3), bcolor(black%20) barw(0.95) || bar value barposition if(category==3 & Treatment==1), bcolor(black) barw(0.95) || bar value barposition if(category==3 & Treatment==2), bcolor(black%60) barw(0.95) || bar value barposition if(category==3 & Treatment==3), bcolor(black%20) barw(0.95) || bar value barposition if(category==4 & Treatment==1), bcolor(black) barw(0.95) || bar value barposition if(category==4 & Treatment==2), bcolor(black%60) barw(0.95) || bar value barposition if(category==4 & Treatment==3), bcolor(black%20) barw(0.95) || rcap lower* upper* barposition, lwidth(medthick) lcolor(black) msize(huge) yscale(range(0(0.05)0.3)) xlabel(2 `" "Independent" "(Chi2 = 0.01)" "' 6 `" "Own List" "(Chi2 = 0.51)" "' 10 `" "Leave politics" "(Chi2 = 1.55)" "' 14 `" "Point to others" "(Chi2 = 7.54**)" "', noticks labgap(6)) xtitle("") ytitle("") title("All respondents") legend(order(1 "Unspecified" 2 "Financial" 3 "Sex") row(1) ) graphregion(fcolor(white)) graphregion(margin(l+10 r+10))


restore 

drop value* lower* upper* ones

graph save "Graph" "$inpath\figure3all.gph", replace



* Figure 3 MEN

foreach x in BecomeIndep_yn SetOwnList_yn LeavePolitics_yn PointOthers_yn {
	ttest `x' if Indep==0 & Male==1, by(Generic)
	scalar lowerGen`x'=r(mu_2)-(r(sd_2)/sqrt(r(N_2))*1.96)
	scalar upperGen`x'=r(mu_2)+(r(sd_2)/sqrt(r(N_2))*1.96)
}

gen lower1 = lowerGenBecomeIndep_yn if Generic==1 & Indep==0 & Male==1
gen lower2 = lowerGenSetOwnList_yn if Generic==1 & Indep==0 & Male==1
gen lower3 = lowerGenLeavePolitics_yn if Generic==1 & Indep==0 & Male==1
gen lower4 = lowerGenPointOthers_yn if Generic==1 & Indep==0 & Male==1

gen upper1 = upperGenBecomeIndep_yn if Generic==1 & Indep==0 & Male==1
gen upper2 = upperGenSetOwnList_yn if Generic==1 & Indep==0 & Male==1
gen upper3 = upperGenLeavePolitics_yn if Generic==1 & Indep==0 & Male==1
gen upper4 = upperGenPointOthers_yn if Generic==1 & Indep==0 & Male==1

gen value1 = BecomeIndep_yn if Generic==1 & Indep==0 & Male==1
gen value2 = SetOwnList_yn if Generic==1 & Indep==0 & Male==1
gen value3 = LeavePolitics_yn if Generic==1 & Indep==0 & Male==1
gen value4 = PointOthers_yn if Generic==1 & Indep==0 & Male==1


foreach x in BecomeIndep_yn SetOwnList_yn LeavePolitics_yn PointOthers_yn {
	ttest `x' if Indep==0 & Male==1, by(Expense)
	scalar lowerExp`x'=r(mu_2)-(r(sd_2)/sqrt(r(N_2))*1.96)
	scalar upperExp`x'=r(mu_2)+(r(sd_2)/sqrt(r(N_2))*1.96)
}

replace lower1 = lowerExpBecomeIndep_yn if Expense==1 & Indep==0 & Male==1
replace lower2 = lowerExpSetOwnList_yn if Expense==1 & Indep==0 & Male==1
replace lower3 = lowerExpLeavePolitics_yn if Expense==1 & Indep==0 & Male==1
replace lower4 = lowerExpPointOthers_yn if Expense==1 & Indep==0 & Male==1

replace upper1 = upperExpBecomeIndep_yn if Expense==1 & Indep==0 & Male==1
replace upper2 = upperExpSetOwnList_yn if Expense==1 & Indep==0 & Male==1
replace upper3 = upperExpLeavePolitics_yn if Expense==1 & Indep==0 & Male==1
replace upper4 = upperExpPointOthers_yn if Expense==1 & Indep==0 & Male==1

replace value1 = BecomeIndep_yn if Expense==1 & Indep==0 & Male==1
replace value2 = SetOwnList_yn if Expense==1 & Indep==0 & Male==1
replace value3 = LeavePolitics_yn if Expense==1 & Indep==0 & Male==1
replace value4 = PointOthers_yn if Expense==1 & Indep==0 & Male==1


foreach x in BecomeIndep_yn SetOwnList_yn LeavePolitics_yn PointOthers_yn {
	ttest `x' if Indep==0 & Male==1, by(Metoo)
	scalar lowerMeT`x'=r(mu_2)-(r(sd_2)/sqrt(r(N_2))*1.96)
	scalar upperMeT`x'=r(mu_2)+(r(sd_2)/sqrt(r(N_2))*1.96)
}

replace lower1 = lowerMeTBecomeIndep_yn if Metoo==1 & Indep==0 & Male==1
replace lower2 = lowerMeTSetOwnList_yn if Metoo==1 & Indep==0 & Male==1
replace lower3 = lowerMeTLeavePolitics_yn if Metoo==1 & Indep==0 & Male==1
replace lower4 = lowerMeTPointOthers_yn if Metoo==1 & Indep==0 & Male==1

replace upper1 = upperMeTBecomeIndep_yn if Metoo==1 & Indep==0 & Male==1
replace upper2 = upperMeTSetOwnList_yn if Metoo==1 & Indep==0 & Male==1
replace upper3 = upperMeTLeavePolitics_yn if Metoo==1 & Indep==0 & Male==1
replace upper4 = upperMeTPointOthers_yn if Metoo==1 & Indep==0 & Male==1

replace value1 = BecomeIndep_yn if Metoo==1 & Indep==0 & Male==1
replace value2 = SetOwnList_yn if Metoo==1 & Indep==0 & Male==1
replace value3 = LeavePolitics_yn if Metoo==1 & Indep==0 & Male==1
replace value4 = PointOthers_yn if Metoo==1 & Indep==0 & Male==1

gen ones=1

preserve 

reshape long value lower upper, i(id Treatment) j(category)
collapse (mean) value lower upper, by(category Treatment)
sort category Treatment 
gen barposition=_n

twoway bar value barposition if(category==1 & Treatment==1), bcolor(black) barw(0.95) || bar value barposition if(category==1 & Treatment==2), bcolor(black%60) barw(0.95) || bar value barposition if(category==1 & Treatment==3), bcolor(black%20) barw(0.95) || bar value barposition if(category==2 & Treatment==1), bcolor(black) barw(0.95) || bar value barposition if(category==2 & Treatment==2), bcolor(black%60) barw(0.95) || bar value barposition if(category==2 & Treatment==3), bcolor(black%20) barw(0.95) || bar value barposition if(category==3 & Treatment==1), bcolor(black) barw(0.95) || bar value barposition if(category==3 & Treatment==2), bcolor(black%60) barw(0.95) || bar value barposition if(category==3 & Treatment==3), bcolor(black%20) barw(0.95) || bar value barposition if(category==4 & Treatment==1), bcolor(black) barw(0.95) || bar value barposition if(category==4 & Treatment==2), bcolor(black%60) barw(0.95) || bar value barposition if(category==4 & Treatment==3), bcolor(black%20) barw(0.95) || rcap lower* upper* barposition, lwidth(medthick) lcolor(black) msize(huge) yscale(range(0(0.05)0.3)) xlabel(2 `" "Independent" "(Chi2 = 0.80)" "' 6 `" "Own List" "(Chi2 = 0.77)" "' 10 `" "Leave politics" "(Chi2 = 1.04)" "' 14 `" "Point to others" "(Chi2 = 1.31)" "', noticks labgap(6)) xtitle("") ytitle("") title("Male respondents") legend(order(1 "Unspecified" 2 "Financial" 3 "Sex") row(1) ) graphregion(fcolor(white))

restore 

drop value* lower* upper* ones

graph save "Graph" "$inpath\figure3men.gph", replace


* Figure 3 WOMEN

foreach x in BecomeIndep_yn SetOwnList_yn LeavePolitics_yn PointOthers_yn {
	ttest `x' if Indep==0 & Male==0, by(Generic)
	scalar lowerGen`x'=r(mu_2)-(r(sd_2)/sqrt(r(N_2))*1.96)
	scalar upperGen`x'=r(mu_2)+(r(sd_2)/sqrt(r(N_2))*1.96)
}

gen lower1 = lowerGenBecomeIndep_yn if Generic==1 & Indep==0 & Male==0
gen lower2 = lowerGenSetOwnList_yn if Generic==1 & Indep==0 & Male==0
gen lower3 = lowerGenLeavePolitics_yn if Generic==1 & Indep==0 & Male==0
gen lower4 = lowerGenPointOthers_yn if Generic==1 & Indep==0 & Male==0

gen upper1 = upperGenBecomeIndep_yn if Generic==1 & Indep==0 & Male==0
gen upper2 = upperGenSetOwnList_yn if Generic==1 & Indep==0 & Male==0
gen upper3 = upperGenLeavePolitics_yn if Generic==1 & Indep==0 & Male==0
gen upper4 = upperGenPointOthers_yn if Generic==1 & Indep==0 & Male==0

gen value1 = BecomeIndep_yn if Generic==1 & Indep==0 & Male==0
gen value2 = SetOwnList_yn if Generic==1 & Indep==0 & Male==0
gen value3 = LeavePolitics_yn if Generic==1 & Indep==0 & Male==0
gen value4 = PointOthers_yn if Generic==1 & Indep==0 & Male==0


foreach x in BecomeIndep_yn SetOwnList_yn LeavePolitics_yn PointOthers_yn {
	ttest `x' if Indep==0 & Male==0, by(Expense)
	scalar lowerExp`x'=r(mu_2)-(r(sd_2)/sqrt(r(N_2))*1.96)
	scalar upperExp`x'=r(mu_2)+(r(sd_2)/sqrt(r(N_2))*1.96)
}

replace lower1 = lowerExpBecomeIndep_yn if Expense==1 & Indep==0 & Male==0
replace lower2 = lowerExpSetOwnList_yn if Expense==1 & Indep==0 & Male==0
replace lower3 = lowerExpLeavePolitics_yn if Expense==1 & Indep==0 & Male==0
replace lower4 = lowerExpPointOthers_yn if Expense==1 & Indep==0 & Male==0

replace upper1 = upperExpBecomeIndep_yn if Expense==1 & Indep==0 & Male==0
replace upper2 = upperExpSetOwnList_yn if Expense==1 & Indep==0 & Male==0
replace upper3 = upperExpLeavePolitics_yn if Expense==1 & Indep==0 & Male==0
replace upper4 = upperExpPointOthers_yn if Expense==1 & Indep==0 & Male==0

replace value1 = BecomeIndep_yn if Expense==1 & Indep==0 & Male==0
replace value2 = SetOwnList_yn if Expense==1 & Indep==0 & Male==0
replace value3 = LeavePolitics_yn if Expense==1 & Indep==0 & Male==0
replace value4 = PointOthers_yn if Expense==1 & Indep==0 & Male==0


foreach x in BecomeIndep_yn SetOwnList_yn LeavePolitics_yn PointOthers_yn {
	ttest `x' if Indep==0 & Male==0, by(Metoo)
	scalar lowerMeT`x'=r(mu_2)-(r(sd_2)/sqrt(r(N_2))*1.96)
	scalar upperMeT`x'=r(mu_2)+(r(sd_2)/sqrt(r(N_2))*1.96)
}

replace lower1 = lowerMeTBecomeIndep_yn if Metoo==1 & Indep==0 & Male==0
replace lower2 = lowerMeTSetOwnList_yn if Metoo==1 & Indep==0 & Male==0
replace lower3 = lowerMeTLeavePolitics_yn if Metoo==1 & Indep==0 & Male==0
replace lower4 = lowerMeTPointOthers_yn if Metoo==1 & Indep==0 & Male==0

replace upper1 = upperMeTBecomeIndep_yn if Metoo==1 & Indep==0 & Male==0
replace upper2 = upperMeTSetOwnList_yn if Metoo==1 & Indep==0 & Male==0
replace upper3 = upperMeTLeavePolitics_yn if Metoo==1 & Indep==0 & Male==0
replace upper4 = upperMeTPointOthers_yn if Metoo==1 & Indep==0 & Male==0

replace value1 = BecomeIndep_yn if Metoo==1 & Indep==0 & Male==0
replace value2 = SetOwnList_yn if Metoo==1 & Indep==0 & Male==0
replace value3 = LeavePolitics_yn if Metoo==1 & Indep==0 & Male==0
replace value4 = PointOthers_yn if Metoo==1 & Indep==0 & Male==0

gen ones=1

preserve 

reshape long value lower upper, i(id Treatment) j(category)
collapse (mean) value lower upper, by(category Treatment)
sort category Treatment 
gen barposition=_n

twoway bar value barposition if(category==1 & Treatment==1), bcolor(black) barw(0.95) || bar value barposition if(category==1 & Treatment==2), bcolor(black%60) barw(0.95) || bar value barposition if(category==1 & Treatment==3), bcolor(black%20) barw(0.95) || bar value barposition if(category==2 & Treatment==1), bcolor(black) barw(0.95) || bar value barposition if(category==2 & Treatment==2), bcolor(black%60) barw(0.95) || bar value barposition if(category==2 & Treatment==3), bcolor(black%20) barw(0.95) || bar value barposition if(category==3 & Treatment==1), bcolor(black) barw(0.95) || bar value barposition if(category==3 & Treatment==2), bcolor(black%60) barw(0.95) || bar value barposition if(category==3 & Treatment==3), bcolor(black%20) barw(0.95) || bar value barposition if(category==4 & Treatment==1), bcolor(black) barw(0.95) || bar value barposition if(category==4 & Treatment==2), bcolor(black%60) barw(0.95) || bar value barposition if(category==4 & Treatment==3), bcolor(black%20) barw(0.95) || rcap lower* upper* barposition, lwidth(medthick) lcolor(black) msize(huge) yscale(range(0(0.05)0.3)) xlabel(2 `" "Independent" "(Chi2 = 2.32)" "' 6 `" "Own List" "(Chi2 = 1.84)" "' 10 `" "Leave politics" "(Chi2 = 0.59)" "' 14 `" "Point to others" "(Chi2 = 11.13***)" "', noticks labgap(6)) xtitle("") ytitle("") title("Female respondents") legend(order(1 "Unspecified" 2 "Financial" 3 "Sex") row(1) ) graphregion(fcolor(white))

restore 

drop value* lower* upper* ones

graph save "Graph" "$inpath\figure3women.gph", replace

graph combine figure3men.gph figure3women.gph, iscale(.6) graphregion(fcolor(white))
graph save "Graph" "$inpath\figure3both.gph", replace
graph combine figure3all.gph figure3both.gph, rows(2) graphregion(fcolor(white))